package com.javatom.notes.alibaba;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description:
 * @author: 曾维录
 * @time: 2019/8/13 16:44
 */
@RestController
public class SentinelTestContrllor {

    @GetMapping(value = "/echo/{string}")
    public String echo(@PathVariable String string) {
        return "Hello Nacos Discovery " + string;
    }


    @GetMapping(value = "/test")
    @SentinelResource(value = "test", blockHandler = "testhandleException")
    public ResultMap test() {

        return ResultMap.successData("按照资源名称限流测试");
    }
    public ResultMap testhandleException(BlockException exception) {
        return ResultMap.success("限流啦",exception.getClass().getCanonicalName() + "\t 服务不可用");
    }

    @GetMapping(value = "/test2")
    @SentinelResource(value = "test2")
    public ResultMap test2() {

        return ResultMap.successData("按照byUrl限流测试");
    }

    @GetMapping(value = "/test3")
    @SentinelResource(value = "test3",
            blockHandlerClass = CustomerBlockHandler.class
    ,blockHandler = "testhandleException")
    public ResultMap test3() {

        return ResultMap.successData("通过CustomerBlockHandler返回自定义信息");
    }


}
